<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20" >
			<u-search placeholder="请输入作业单号或作业内容搜索" :clearabled="true" v-model="keyword" border-color="#606266" @custom="search" @search="search"></u-search>
		</view>
		<u-card padding="16" v-for="item in dataList" :key="item.id">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="10">
							<view class="title">
								<span>作业内容：</span><span>{{item.name}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body" @click="toDetailed(item.id)">
				<view class="wrap">
					<u-row>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10 weikaishi" v-if="item.status == '未开始'">
								<span>状态：</span><span>{{item.status}}</span>
							</view>
							<view class="u-line-1 u-m-t-10 jinxingzhong" v-else-if="item.status == '作业中'">
								<span>状态：</span><span>{{item.status}}</span>
							</view>
							<view class="u-line-1 u-m-t-10 yizuofei" v-else-if="item.status == '作废'">
								<span>状态：</span><span>{{item.status}}</span>
							</view>
							<view class="u-line-1 u-m-t-10 yiwancheng" v-else>
								<span>状态：</span><span>{{item.status}}</span>
							</view>
						</u-col>
						<u-col span="6" >
							<view class="u-line-1 u-m-t-10">
								<span>作业日期：</span><span>{{item.v1}}</span>
							</view>
						</u-col>
						
					</u-row>
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>客户：</span><span>{{item.outCustomerName}}</span>
							</view>
						</u-col>
						<u-col span="6" >
							<view class="u-line-1 u-m-t-10">
								<span>项目部：</span><span>{{item.operateName}}</span>
							</view>
						</u-col>
						
					</u-row>
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>单号：</span><span>{{item.orderNumber}}</span>
							</view>
						</u-col>
						<u-col span="6" >
							<view class="u-line-1 u-m-t-10">
								<span>客户单号：</span><span>{{item.customerNumber}}</span>
							</view>
						</u-col>
						
					</u-row>
					<u-row >
						<u-col span="6" >
							<view class="u-line-1 u-m-t-10">
								<span>类型：</span><span>{{item.taskWork}}</span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>类别：</span><span>{{item.v8}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>车型：</span><span>{{item.carModel}}</span>
							</view>
						</u-col>
						<u-col span="6" v-if="item.taskWork == '跟车'">
							<view class="u-line-1 u-m-t-10">
								<span>门店数：</span><span>{{item.v9}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="6" >
							<view class="u-line-1 u-m-t-10">
								<span>实时人数：</span><span>{{item.v6}}</span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>累计人数：</span><span>{{item.peoples}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>核算方式：</span><span>{{item.settlementMode}}</span>
							</view>
						</u-col>
						<u-col span="6" v-if="item.settlementMode == '体积'">
							<view class="u-line-1 u-m-t-10">
								<span>体积：</span><span>{{item.volume}}</span>
							</view>
						</u-col>
						<u-col span="6" v-if="item.settlementMode == '数量'">
							<view class="u-line-1 u-m-t-10">
								<span>数量：</span><span>{{item.nums}}</span>
							</view>
						</u-col>
						<u-col span="6" v-if="item.settlementMode == '重量'">
							<view class="u-line-1 u-m-t-10">
								<span>重量(吨)：</span><span>{{item.weights}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>时效：</span><span>{{item.prescription}}</span>
							</view>
						</u-col>
						<u-col span="6" >
							<view class="u-line-1 u-m-t-10">
								<span>累计工时：</span><span>{{item.hours}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>开始时间：</span><span v-if="item.createTimes">{{item.createTimes.substring(5, 16)}}</span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>结束时间：</span><span v-if="item.endTime">{{item.endTime.substring(5, 16)}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="foot-butten" slot="foot" v-if="item.status == '已完成' || item.status == '作业中'">
				<view :class="flex">
					<u-col span="12" text-align="center" @click="fee(item)" >
						<view  class="u-m-10 ">
							反馈
						</view>
					</u-col>
				</view>
			</view>
		</u-card>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				dataList: [],
				keyword:'',
			    pageNo: 1,
			    hasMore: true,
			    orderCount: 0,
			}
		},
		onLoad() {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
		},
		onShow() {
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			uni.showLoading({
				title: '加载中'
			})
			if (this.hasMore) {
				this.pageNo++ 
				setTimeout(() => {
					this.loadOrder({
						condition: this.keyword
					}).then(res => {})
					uni.hideLoading()
				}, 500)
			} else {
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '已经到低了哦',
						duration: 2000
					});
				}, 500)
			}
		},
		methods: {
			toDetailed(e){
				this.$Router.push({ 
					name: 'taskdetailed',
					params: { taskid:e },
				})
			},
			fee(e){
				this.$Router.push({ 
					name: 'addfee',
					params: { taskId:e.id,orderNumber:e.orderNumber },
				})
			},
			refresh(){
				this.pageNo = 1
				this.hasMore = true
				this.loadOrder({
					condition: this.keyword
				}).then(res => {
				})
			},
			loadOrder(param = {}) {
				return new Promise((resolve, reject) => {
					param = Object.assign(param, {
						page: this.pageNo,
						limit: 10
					})
					this.$http.post('/rest/task/list',{
					},{
						params: param,
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						if (this.pageNo == 1) {
							this.dataList = res.data.data
						} else {
							this.dataList = this.dataList.concat(res.data.data)
						}
						this.orderCount = res.data.count
						this.hasMore = this.pageNo * 10 < res.data.count
						resolve(res)
					})
				})
			},
			search(e){
				uni.showLoading({
					title: '加载中'
				})
				this.refresh()
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			},
		},
	}
</script>
